package com.tanhua.server.controller;

import cn.hutool.core.convert.Convert;
import com.tanhua.server.service.MyCenterService;
import com.tanhua.server.vo.CountsVo;
import com.tanhua.server.vo.PageResult;
import com.tanhua.server.vo.SettingsVo;
import com.tanhua.server.vo.UserInfoVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RequestMapping("users")
@RestController
@Slf4j
public class MyCenterController {

    @Autowired
    private MyCenterService myCenterService;


    /**
     * 根据用户id查询用户信息
     *
     * @param userId 用户id，如果为空，表示查询当前登录人的信息
     * @return
     */
    @GetMapping
    public UserInfoVo queryUserInfoByUserId(@RequestParam(value = "userID", required = false) Long userId) {
        return this.myCenterService.queryUserInfoByUserId(userId);
    }

    /**
     * 是否喜欢
     *
     * @param userId
     * @return
     */
    @GetMapping("{userId}/alreadyLove")
    public Boolean isLike(@PathVariable("userId") Long userId) {
        return this.myCenterService.isLike(userId);
    }

    /**
     * 互相喜欢，喜欢，粉丝 - 统计
     *
     * @return
     */
    @GetMapping("counts")
    public CountsVo queryCounts() {
        return this.myCenterService.queryCounts();
    }

    /**
     * 更新用户信息
     *
     * @param userInfoVo
     * @return
     */
    @PutMapping
    public Boolean updateUserInfo(@RequestBody UserInfoVo userInfoVo) {
        return this.myCenterService.updateUserInfo(userInfoVo);
    }

    @GetMapping("friends/{type}")
    public PageResult queryLikeList(@PathVariable("type") String type, @RequestParam(value = "page", defaultValue = "1") Integer page,
                                    @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                    @RequestParam(value = "keyword", required = false) String keyword) {
        return this.myCenterService.queryLikeList(Integer.valueOf(type), page, pageSize, keyword);
    }

    /**
     * 取消喜欢
     *
     * @param userId
     */
    @DeleteMapping("like/{uid}")
    public void disLike(@PathVariable("uid") Long userId) {
        this.myCenterService.disLike(userId);
    }

    /**
     * 喜欢粉丝
     *
     * @param userId
     */
    @PostMapping("fans/{uid}")
    public void likeFan(@PathVariable("uid") Long userId) {
        this.myCenterService.likeFan(userId);
    }

    /**
     * 查询配置
     *
     * @return
     */
    @GetMapping("settings")
    public SettingsVo querySettings() {
        return this.myCenterService.querySettings();

    }

    /**
     * 保存陌生人问题
     *
     * @param param
     * @return
     */
    @PostMapping("questions")
    public Object saveQuestions(@RequestBody Map<String,Object> param){
        String content = Convert.toStr(param.get("content"));
        this.myCenterService.saveQuestions(content);
        return null;
    }

    /**
     * 查询黑名单
     *
     * @param page
     * @param pageSize
     * @return
     */
    @GetMapping("blacklist")
    public PageResult queryBlackList(@RequestParam(value = "page", defaultValue = "1") Integer page,
                                     @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize){
        return this.myCenterService.queryBlackList(page,pageSize);
    }

    /**
     * 移除黑名单
     *
     * @return
     */
    @DeleteMapping("blacklist/{uid}")
    public Object deleteBlackUser(@PathVariable("uid") Long blackUserId) {
        return   myCenterService.deleteBlackUser(blackUserId);
    }

    /**
     * 更新设置
     *
     * @param param
     * @return
     */
    @PostMapping("notifications/setting")
    public Object updateNotifications(@RequestBody Map<String,Boolean> param){
        Boolean likeNotification = param.get("likeNotification");
        Boolean pinglunNotification = param.get("pinglunNotification");
        Boolean gonggaoNotification = param.get("gonggaoNotification");
       return this.myCenterService.updateNotifications(likeNotification,pinglunNotification,gonggaoNotification);
    }
}
